package com.guoxin.concurrentprogramming.chapter6;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author guoxin
 * @date 2019/9/19
 */
public class CompletableFutureException {
    public static Integer calc(Integer para){
        return para/0;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        final CompletableFuture<Void> fu = CompletableFuture
                .supplyAsync(() -> calc(50))
                .exceptionally(ex -> {
                    System.out.println(ex.getMessage());
                    return 0;
                })
                .thenApply((i) -> Integer.toString(i))
                .thenApply((str) -> "\"" +str+ "\"")
                .thenAccept(System.out::println);
        fu.get();
    }
}
